package com.four.controller;

import com.four.pojo.Make;
import com.four.service.IMakeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Controller("makeController")
public class MakeController {
    @Autowired
    @Qualifier("makeServiceImpl")
    private IMakeService makeService;
    //查询全部
    @RequestMapping("/makeFindAll")
    public String findAll(Model model){
        List<Make> list = makeService.findAll();
        model.addAttribute("list",list);
        return "Appointment.jsp";
    }
    @RequestMapping(value = "/findAllMake")
    public String findAllMake(Model model){
        List<Make> list = makeService.findAllMake();
        model.addAttribute("list",list);
        return "Hello.jsp";
    }

    //模糊查询
    @RequestMapping("makeFindAllBy")
    public String makeFindAllBy(Make make,Model model){
        System.out.println(make);
        List<Make> list = makeService.makeFindAllBy(make);
        model.addAttribute("list",list);
        return "Appointment.jsp";
    }
    //修改前查询
    @RequestMapping("makeFindAllByMid")
    public String makeFindAllByMid(Model model,int mid){
        Make make = makeService.selectByPrimaryKey(mid);
        model.addAttribute("make",make);
        return "appoint_Detail.jsp";
    }
    @RequestMapping("/makeDelete")
    public String makeDelete(int mid){
        makeService.deleteByPrimaryKey(mid);
        return "redirect:/makeFindAll";
    }
    //修改
    @RequestMapping("makeUpdateFindByMid")
    public String makeUpdateFindByMid(Make make){
        makeService.updateByPrimaryKeySelective(make);
        return "redirect:/makeFindAll";
    }
    @RequestMapping("/addMark")
    public String addMark(Make make){
        make.setmState("已预约");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        make.setmTime(sdf.format(date));
        System.out.println(make);
        makeService.insertSelective(make);
        return "redirect:/makeFindAll";
    }


}
